package com.falcon.authority.service.impl;


import com.falcon.authority.domain.dos.ApiDO;
import com.falcon.authority.domain.po.ApiPO;
import com.falcon.authority.domain.req.ApiQuery;
import com.falcon.authority.mapper.IApiMapper;
import com.falcon.authority.service.IApiService;
import com.falcon.core.service.AbsBaseService;
import com.falcon.core.utils.BeanUtils;
import com.swan.core.utils.collection.TreeUtil;
import com.swan.mybatis.mapper.mapper.IBaseMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
public class ApiService extends AbsBaseService<ApiPO> implements IApiService {

    @Autowired
    private IApiMapper apiMapper;

    @Override
    public IBaseMapper<Long, ApiPO> getMapper() {
        return this.apiMapper;
    }

    @Override
    public List<ApiDO> queryTree(ApiQuery request) {

        // 查询所有
        List<ApiPO> list = this.queryList(request);

        List<ApiDO> apiDOS = BeanUtils.copyToList(list, ApiDO.class);

        // 构建树
        List<ApiDO> treeList = TreeUtil.buildSimpleTree(apiDOS, ApiDO::getId, ApiDO::getParentId,0l);

        return treeList;
    }


}

